<?php

use core\test\PHPUnitTest;
use core\utils\CurlUtil;

class TestIndexController extends PHPUnitTest {

    public function testIndex() {
        $res = CurlUtil::get('http://localhost/a?b[]=1');
        $this->assertEquals($res, 'a');
        $res = CurlUtil::get('http://localhost/ap/test?b[]=1');
        $this->assertEquals($res, 'test1');
    }
    public function testPost() {
        $res = CurlUtil::get('http://localhost/index/postTest', [], [], [CURLOPT_HEADER=>true]);
        $this->assertTrue(strpos(explode("\n", $res)[0], '405') !== false);

        $param = ['k'=>'v', 'double'=>[1,2]];
        $res = CurlUtil::post('http://localhost/index/postTest', $param, [], []);
        $res = json_decode($res, true);
        $this->assertEquals($param, $res);
    }
    public function testUrlPreg() {
        $res = CurlUtil::get('http://localhost/ab/test?b[]=1');
        $this->assertEquals($res, 'test1');
        $res1 = CurlUtil::get('http://localhost/ac/test?b[]=1');
        $this->assertEquals($res1, 'test1');
    }
}